﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;
using Honestysoft.Baseframework.WebUI;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
    public partial class SelectFGWAT : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            //Bu_AuditTable_FGW item = Session[AuditSummaryUtils.FWGSessionID] as Bu_AuditTable_FGW;
            DataTable dt = AuditSummaryUtils.ThisTimeFGWSession.BatchSummaryDetail.Copy();
            if (AuditSummaryUtils.ThisTimeFGWSession.ThisTimeAT != null && AuditSummaryUtils.ThisTimeFGWSession.ThisTimeAT.Rows.Count > 0)
            {
                for (int i = dt.Rows.Count - 1; i >= 0; i--)
                {
                    if (AuditSummaryUtils.ThisTimeFGWSession.ThisTimeAT.Select("ATID='" + dt.Rows[i]["ID"].ToString() + "'").Length > 0)
                    {
                        dt.Rows.RemoveAt(i);
                    }
                }
            }
            DataTable dtOtherAT = new Honestysoft.Financing.BusinessLogic.Audit(Globals.CurrentConnStringName).GetOtherCounterAT(AuditSummaryUtils.ThisTimeFGWSession.BatchID, AuditSummaryUtils.ThisTimeFGWSession.Counter);
            if (dtOtherAT != null && dtOtherAT.Rows.Count > 0)
            {
                for (int i = dt.Rows.Count - 1; i >= 0; i--)
                {
                    if (dtOtherAT.Select("ATID='" + dt.Rows[i]["ID"].ToString() + "'").Length > 0)
                    {
                        dt.Rows.RemoveAt(i);
                    }
                }
            }
            rptList.DataSource = dt;
            rptList.DataBind();
        }

        protected string GetPDocRec(decimal amount_DocRec_S,decimal tAmount_C_A_S, decimal amount_C_S)
        {
            if (amount_C_S == 0) { return "0%"; }
            return string.Format("{0:P}", (amount_DocRec_S + tAmount_C_A_S) / amount_C_S);
        }

        protected string GetPS(decimal amount_S, decimal tAmount_C_A_S, decimal amount_C_S)
        {
            if (amount_C_S == 0) { return "0%"; }
            return string.Format("{0:P}", (amount_S + tAmount_C_A_S) / amount_C_S);
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "ret", "window.returnValue='" + Request["chkID"] + "';window.close();", true);
        }
    }
}